﻿using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
using YAKEJI.Abp.Domain.Repositories;
using YAPACS.BusinessObjects.Exams;
using YAPACS.Organizations;
using YAPACS.RisServer.Abstractions;

namespace YAPACS.RisServer.Services;

public class ExamEventService(IRepository<ExamEvent, Guid> eventRepository, IRepository<ApplicationUser, Guid> userRepository, ICurrentUserOrganization currentUserOrganization) : DomainService, IExamEventService, ITransientDependency
{
    private readonly IRepository<ExamEvent, Guid> _eventRepository = eventRepository;
    private readonly IRepository<ApplicationUser, Guid> _userRepository = userRepository;
    private readonly ICurrentUserOrganization _currentUserOrganization = currentUserOrganization;

    public async Task AddExamEventAsync(Exam exam, string eventType, string eventContent = null)
    {
        var user = await _userRepository.GetAsync(_currentUserOrganization.UserId);
        var examEvent = await _eventRepository.NewEntityAsync();
        examEvent.EventContent = eventContent;
        examEvent.EventType = eventType;
        examEvent.Operator = user;
        examEvent.EventTime = Clock.Now;
        exam.ExamEvents.Add(examEvent);
    }
}
